//1.引入样式表
//公用样式 
require('../../assets/css/index.less');
require('../../assets/fonts/iconfont.css');

// 引入weUI
//引入样式
require('../../lib/weui/weui.css');
//引入js库
let weui = require('../../lib/weui/weui.js');
//引入echarts 
import * as echarts from 'echarts';

// 当前页面样式
require('./sportData.less')

//2.引入工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');
const local = require('../../utils/local');



// 3.当前页面的js
dom.ready(function () {
    //echart使用
    function fn(xdata, ydata) {
        //1.初始化
        let myCharts = echarts.init(dom.getEle('#ebox'))

        //2.配置项
        let option = {
            // 标题
            title: {
                text: '最近7天运动时长'
            },
            // x轴
            xAxis: {
                type: 'category',
                data: xdata,
                axisLabel: {
                    // interval: 0,
                    rotate:45
                },
                axisTick: {
                    //x轴刻度相关设置
                    alignWithLabel: true,
                }
            },
            // y轴
            yAxis: {
                type: 'value'
            },
            //数据项
            series: [
                {
                    data: ydata,
                    type: 'bar'
                }
            ]
        };
        //3.设置option到myCharts中
        myCharts.setOption(option);
    }



    //获取当前用户运动数据\
    function getUserSportData() {
        https.get('/api/exercise', function (res) {
            // console.log(res);
            //判定
            if (res.errno == 0) {
                console.log(res.data);
                //处理数据
                // x轴
                let xD = res.data.days.map(v => v.date.slice(5));
                let yD = res.data.days.map(v => v.sumDuration);
                console.log(xD);
                //渲染第一个echarts
                fn(xD, yD)
            }
        })
    }

    //调用
    getUserSportData()



})